<template>
  <div class="app-container">

    <div class="Search">
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="query" >
          <el-form-item v-has="'PLATFROM_TENANT_QUERY'">
            <el-cascader ref="tenantTree" placeholder="所属租户" :props="tenantProps" :options="tenantOptions"
              @change="selectTenant" clearable collapse-tags filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader ref="organTree" placeholder="所属组织" :props="props" :options="organOptions" @change="selectOrgan"
              collapse-tags clearable filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader ref="goodsTypeTree" placeholder="商品分类" :props="goodsTypeTreeProps"
              :options="goodsTypeTreeOptionData" @change="selectGoodsType(query.params)" filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader ref="supplierTree" placeholder="供应商" :props="supplierProps" :options="supplierOptions"
              @change="selectSupplier" clearable collapse-tags filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.goodsName" placeholder="商品名称" clearable />
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.goodsName" placeholder="SKU名称" />
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.goodsCode" placeholder="SKU编码" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">发布SKU</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="success" plain icon="el-icon-sell" size="mini" @click="handleToOnSale">批量上架</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="danger" plain icon="el-icon-sold-out" size="mini" @click="handleToSoldOut">批量下架</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>
    <div class="block">
      <el-table v-loading="listLoading" :data="list" element-loading-text="Loading"
        @selection-change="handleSelectionChange" border fit highlight-current-row>

        <el-table-column type="selection" width="45">
        </el-table-column>
        <el-table-column label="SKU名称" width="110">
          <template slot-scope="scope">
            {{ scope.row.goodsName }}
          </template>
        </el-table-column>
        <el-table-column label="SKU编码" width="110">
          <template slot-scope="scope">
            {{ scope.row.goodsCode }}
          </template>
        </el-table-column>
        <el-table-column label="关联商品" width="110">
          <template slot-scope="scope">
            {{ scope.row.goodsId }}
          </template>
        </el-table-column>
        <el-table-column label="商品图片url" width="110">
          <template slot-scope="scope">
            <el-image style="width: 100px; height: 100px" :src="scope.row.goods.goodsImg">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column label="所属组织" width="110">
          <template slot-scope="scope">
            {{ scope.row.organId }}
          </template>
        </el-table-column>
        <el-table-column label="库存" width="110">
          <template slot-scope="scope">
            {{ scope.row.stockCount }}
          </template>
        </el-table-column>
        <el-table-column label="价格(单位：分)" width="110">
          <template slot-scope="scope">
            {{ scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column label="备注" width="110">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column>

        <el-table-column align="center" fixed="right" prop="created_at" label="操作" width="200">
          <template slot-scope="scope">
            <el-link type="warning" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">
              修改
            </el-link>
            <el-link type="danger" icon="el-icon-plus" @click="handleDelete(scope.$index, scope.row)">
              删除
            </el-link>
            <el-link v-if="scope.row.status === 64" v-has="'GOODS_ADD'" type="success" size="mini" icon="el-icon-sell"
              @click="handlePutOnSale(scope.$index, scope.row)">上架</el-link>

            <el-link v-if="scope.row.status === 32" v-has="'GOODS_ADD'" type="warning" icon="el-icon-sold-out" size="mini"
              @click="handlePutSoldOut(scope.$index, scope.row)">下架</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
        @current-change="handleCurrentChange" />
    </div>
    <div class="block">
      <!--弹框-->
      <el-dialog :title="titleMap[dialogStatus]" width="68%" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item v-if="addForVisible" label="主键">
            <el-input v-model="form.id" placeholder="主键" auto-complete="off" />
          </el-form-item>
          <el-form-item label="关联商品">
            <el-input v-model="form.goodsId" placeholder="关联商品" auto-complete="off" />
          </el-form-item>
          <el-form-item label="SKU名称">
            <el-input v-model="form.goodsName" placeholder="SKU名称" auto-complete="off" />
          </el-form-item>
          <el-form-item label="SKU编码">
            <el-input v-model="form.goodsCode" placeholder="SKU编码" auto-complete="off" />
          </el-form-item>
          <el-form-item label="所属组织">
            <el-input v-model="form.organId" placeholder="所属组织" auto-complete="off" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" placeholder="备注" auto-complete="off" />
          </el-form-item>
          <el-form-item label="价格(单位：分)">
            <el-select v-model="form.price" placeholder="价格(单位：分)">
              <el-option v-for="item in query.options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleEditSave">确 定</el-button>
        </div>
      </el-dialog>
    </div>


    <div class="block">
      <el-drawer title="SKU发布" size="100%" :visible.sync="drawer" :direction="direction" :before-close="handleClose">

        <div class="app-container">
          <el-form ref="form" :model="form" :inline="true" >

            <el-form-item label="商品分类">
              <el-cascader v-model="form.goodsTypeId" ref="goodsTypeTree" placeholder="商品分类" :props="goodsTypeTreeProps"
                :options="goodsTypeTreeOptionData" @change="selectGoodsType(form)" filterable></el-cascader>
            </el-form-item>

            <el-form-item label="商品名称" style="width: 280px">
              <el-input v-model="tempGoods.goodsName" suffix-icon="el-icon-date" @focus="handleShowGoodsList"></el-input>
            </el-form-item>
          </el-form>

          <el-steps :active="step" simple>
            <el-step title="属性选择" icon="el-icon-edit">
            </el-step>
            <el-step title="规格选择" icon="el-icon-upload">
            </el-step>
            <el-step title="SKU编辑" icon="el-icon-picture"></el-step>
          </el-steps>

          <div v-show="step == 1">
            <el-card class="box-card" style="margin: 10px 0 0 0;" shadow="hover">
              <div slot="header" class="clearfix">
                <span>属性选择:</span> <span style="font-size: x-small;">请至少选择一个属性</span>
                <el-button style="float: right;" type="primary" icon="el-icon-edit" round
                  @click="handleShowQueryGoodsTypeProps">添加属性选择项</el-button>
              </div>
              <div class="text item">
                <el-form ref="form" :model="form" :inline="false" label-width="80px">
                  <el-form-item v-for="goodsTypeProps in chooseGoodsTypePropsNodes" :label="goodsTypeProps.propName">
                    <el-checkbox-group @change="handleGoodsTypePropsChange" v-model="skuPropsSpecifications.props">
                      <el-checkbox v-for="goodsTypePropsValue in goodsTypeProps.goodsTypePropValues"
                        :label="goodsTypePropsValue.id" :name="goodsTypePropsValue.id">{{
                          goodsTypePropsValue.goodsPropsValue }}</el-checkbox>
                    </el-checkbox-group>
                  </el-form-item>
                </el-form>
              </div>
              <div class="bottom clearfix">
                <el-button style="float: right;" type="primary" @click="handleCheckGoodsTypeProps">下一步</el-button>
              </div>
            </el-card>
          </div>

          <div v-show="step == 2">
            <el-card class="box-card" style="margin: 10px 0 0 0;" shadow="hover">
              <div slot="header" class="clearfix">
                <span>规格选择</span>
                <el-button style="float: right;" type="primary" icon="el-icon-edit" round
                  @click="handleShowGoodsSpecification">添加规格选择项</el-button>
              </div>
              <div class="text item">
                <el-form ref="form" :model="form" :inline="false" label-width="80px">
                  <el-form-item v-for="specification in chooseSpecificationNodes" :label="specification.parameterName">
                    <el-checkbox-group @change="handleGoodsSpecificationItemChange"
                      v-model="skuPropsSpecifications.specifications">
                      <el-checkbox v-for="specificationItem in specification.specificationItems"
                        :label="specificationItem.id" :name="specificationItem.id">{{ specificationItem.specificationValue
                        }}</el-checkbox>
                    </el-checkbox-group>
                  </el-form-item>
                </el-form>
              </div>
              <div class="bottom clearfix">
                <el-button style="float: right; margin: 0 0 0 10px;" type="primary"
                  @click="handleCheckGoodsSpecification">下一步</el-button>
                <el-button style="float: right;" type="primary" @click="handleGoTOPreStep">上一步</el-button>
              </div>
            </el-card>
          </div>

          <div v-show="step == 3">
            <el-card class="box-card" style="margin: 10px 0 0 0;" shadow="hover">
              <div slot="header" class="clearfix">
                <span>待发布SKU</span>
              </div>
              <div class="app-container">
                 <el-table v-loading="listLoading" :data="skuGoods" @header-click="handleBatchEditSkuPropertyValue"
                  element-loading-text="Loading" border fit highlight-current-row>
                  <el-table-column align="center" label="序号" width="45">
                    <template slot-scope="scope">
                      {{ scope.$index }}
                    </template>
                  </el-table-column>
                  <el-table-column label="销售属性" prop="goodsName" width="110">
                    <template slot-scope="scope">
                      {{ scope.row.goodsName }}
                    </template>
                  </el-table-column>
                  <el-table-column label="商品名称" width="110">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.name" placeholder="商品名称" clearable />
                    </template>
                  </el-table-column>
                  <el-table-column label="卖家sku编码" width="110">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.code" placeholder="卖家sku编码" clearable />
                    </template>
                  </el-table-column>
                  <el-table-column label="商品售价(单位:分)" width="110">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.price" placeholder="商品售价(单位:分)" clearable />
                    </template>
                  </el-table-column>
                  <el-table-column label="商品成本价(单位:分)" width="110">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.costPrice" placeholder="商品成本价(单位:分)" clearable />
                    </template>
                  </el-table-column>
                  <el-table-column label="商品建议价(单位:分)" width="110">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.suggestedRetailPrice" placeholder="商品建议价(单位:分)" clearable />
                    </template>
                  </el-table-column>

                  <el-table-column label="是否预售商品" width="150">
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.preSaler" active-value="1" inactive-value="0" active-text="预售"
                        inactive-text="现售">
                      </el-switch>
                    </template>
                  </el-table-column>
                  <el-table-column label="库存" width="110">
                    <template slot-scope="scope">
                      <el-input-number v-model="scope.row.stockCount" placeholder="库存"></el-input-number>
                    </template>
                  </el-table-column>
                  <el-table-column label="图片" width="510">
                    <template slot-scope="scope">
                      <el-upload action="/api/file.allService/FileService/uploadFile" list-type="picture-card"
                        :on-remove="handleRemove" :headers="uploadHeader" :with-credentials="true"
                        :on-preview="handlePreview" :before-remove="beforeRemove" multiple :data='fileUloadParams'
                        :on-success="uploadImageOnSuccess" name="file" :limit="4" :on-exceed="handleExceed"
                        :file-list="scope.row.imageList">
                        <i class="el-icon-plus"></i>
                      </el-upload>
                      <el-dialog :visible.sync="dialogVisible">
                        <img width="100%" :src="scope.row.goodsImg" alt="">
                      </el-dialog>
                    </template>
                  </el-table-column>

                  <el-table-column fixed="right" align="center" prop="created_at" label="操作" width="100">
                    <template slot-scope="scope">
                      <el-link icon="el-icon-delete" type="danger" @click="handleDeleteSku(scope.$index, scope.row)">
                        删除
                      </el-link>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-card>


            <el-card class="box-card" style="margin: 10px 0 0 0;" shadow="hover">
              <div slot="header" class="clearfix">
                <span>包装信息</span>
              </div>
              <div class="text item">
                <el-form ref="form" :model="form" :inline="false" label-width="80px">
                  <el-form-item label="商品毛重">
                    <el-input v-model="form.grossWeight" placeholder="商品毛重(单位：千克)"></el-input>
                  </el-form-item>
                  <el-form-item label="商品净重">
                    <el-input v-model="form.netWeight" placeholder="商品净重(单位：千克)"></el-input>
                  </el-form-item>
                  <el-form-item label="商品尺寸">
                    <el-input v-model="form.length" style="width:33%" placeholder="长(单位：厘米)"></el-input>
                    <el-input v-model="form.width" style="width:33%" placeholder="宽(单位：厘米)"></el-input>
                    <el-input v-model="form.height" style="width:32%" placeholder="高(单位：厘米)"></el-input>
                  </el-form-item>
                  <el-form-item label="包装尺寸">
                    <el-input v-model="form.packLength" style="width:33%" placeholder="长(单位：厘米)"></el-input>
                    <el-input v-model="form.packWidth" style="width:33%" placeholder="宽(单位：厘米)"></el-input>
                    <el-input v-model="form.packHeight" style="width:32%" placeholder="高(单位：厘米)"></el-input>
                  </el-form-item>
                  <el-form-item label="包装清单">
                    <el-input v-model="form.packageInfo" placeholder="包装清单"></el-input>
                  </el-form-item>
                </el-form>
              </div>
              <div class="bottom clearfix">
                <el-button style="float: right; margin: 0 0 0 10px;" type="primary"
                  @click="handleSubmitSKUs">提交</el-button>
                <el-button style="float: right; margin: 0 0 0 10px;" type="primary"
                  @click="handleGoTOPreStep">上一步</el-button>
              </div>
            </el-card>

          </div>
        </div>
      </el-drawer>
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog :title="'商品分类规格选择'" width="78%" :visible.sync="dialogFormShowGoodsSpecificationVisible">
        <div class="Search">
          <!--工具条-->
          <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="query">
              <el-form-item label="规格名称">
                <el-input v-model="query.goodsSpecification.parameterName" placeholder="规格名称" auto-complete="off" />
              </el-form-item>
              <el-form-item label="规格组">
                <el-cascader ref="specificationGroupTree" placeholder="规格组" :props="specificationGroupTreeProps"
                  :options="specificationGroupOptionData" @change="selectSpecificationGroup" filterable></el-cascader>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="handleQueryGoodsTypeSpecification">查询</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </div>
        <el-table v-loading="listLoading" :data="goodsSpecificationList"
          @selection-change="handleGoodsSpecifiactionSelectionChange" element-loading-text="Loading" border fit
          highlight-current-row>
          <el-table-column type="selection" width="40" />
          <el-table-column align="center" label="序号" width="45">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="规格名称" width="110">
            <template slot-scope="scope">
              {{ scope.row.parameterName }}
            </template>
          </el-table-column>

          <el-table-column label="显示区域" width="110">
            <template slot-scope="scope">
              {{ scope.row.displayArea }}
            </template>
          </el-table-column>
          <el-table-column label="商品分类编号" width="110">
            <template slot-scope="scope">
              {{ scope.row.goodsTypeId }}
            </template>
          </el-table-column>
          <el-table-column label="规格组编号" width="110">
            <template slot-scope="scope">
              {{ scope.row.groupId }}
            </template>
          </el-table-column>
          <el-table-column label="备注" width="110">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
          <el-table-column>
            <template slot-scope="scope">
              <el-link v-has="'DICTIONARYORGAN_ASSIGNEDDICTIONARY'" type="success" style="cursor: pointer;"
                @click="handleShowGoodsSpecificationItem(scope.$index, scope.row)">
                查看规格值
              </el-link>
            </template>
          </el-table-column>

        </el-table>
        <div class="block">
          <el-pagination :current-page="query.goodsSpecification.currentPage" :page-sizes="[10, 20, 30, 40]"
            :page-size="query.goodsSpecification.pageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="query.goodsSpecification.total" @size-change="handleQueryGoodsSpecificationSizeChange"
            @current-change="handleQueryGoodsSpecificationCurrentChange" />
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormShowGoodsSpecificationVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleGoodsSpecificationToSKU">确 定</el-button>
        </div>
      </el-dialog>
    </div>


    <div class="block">
      <!--弹框-->
      <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogShowGoodsSpecificationItemVisable">
        <el-table v-loading="listLoading" :data="goodsTypeSpecificationItemList" element-loading-text="Loading" border fit
          highlight-current-row>
          <el-table-column align="center" label="序号" width="58">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="商品规格值" width="110">
            <template slot-scope="scope">
              {{ scope.row.specificationValue }}
            </template>
          </el-table-column>
          <el-table-column label="备注">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination :current-page="query.goodsTypePropsItem.currentPage" :page-sizes="[10, 20, 30, 40]"
            :page-size="query.goodsTypePropsItem.pageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="query.goodsTypePropsItem.total" @size-change="handleQueryItemValSizeChange"
            @current-change="handleQueryItemCurrentChange" />
        </div>

      </el-dialog>
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog :title="'商品分类属性选择'" width="78%" :visible.sync="dialogFormShowGoodsPropsVisible">
        <div class="Search">

          <!--工具条-->
          <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="query">
              <el-form-item label="属性名称">
                <el-input v-model="query.goodsTypeProps.propName" placeholder="规格名称" auto-complete="off" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="handleQueryGoodsTypePropsPage">查询</el-button>
              </el-form-item>
            </el-form>
          </el-col>


        </div>
        <div class="block">
          <el-table v-loading="listLoading" :data="goodsTypePropsList" @selection-change="handleGoodsPropSelectionChange"
            element-loading-text="Loading" border fit highlight-current-row>
            <el-table-column type="selection" width="40" />
            <el-table-column align="center" label="序号" width="45">
              <template slot-scope="scope">
                {{ scope.$index }}
              </template>
            </el-table-column>

            <el-table-column label="分类属性名称" width="110">
              <template slot-scope="scope">
                {{ scope.row.propName }}
              </template>
            </el-table-column>
            <el-table-column label="是否必选" width="110">
              <template slot-scope="scope">
                {{ scope.row.isMust ? '必选' : '非必选' }}
              </template>
            </el-table-column>
            <el-table-column label="关联商品分类" width="110">
              <template slot-scope="scope">
                {{ scope.row.goodsTypeId }}
              </template>
            </el-table-column>
            <el-table-column label="所属组织" width="110">
              <template slot-scope="scope">
                {{ scope.row.organId }}
              </template>
            </el-table-column>
            <el-table-column label="组织路径" width="110">
              <template slot-scope="scope">
                {{ scope.row.organPath }}
              </template>
            </el-table-column>
            <el-table-column label="删除标识" width="110">
              <template slot-scope="scope">
                {{ scope.row.isDeleted }}
              </template>
            </el-table-column>
            <el-table-column label="备注" width="110">
              <template slot-scope="scope">
                {{ scope.row.remark }}
              </template>
            </el-table-column>
          </el-table>
          <div class="block">
            <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange"
              @current-change="handleCurrentChange" />
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormShowGoodsPropsVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleGoodsTypePropsToSKU">确 定</el-button>
        </div>
      </el-dialog>
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog :title="'选择发布的SKU商品'" width="78%" :visible.sync="dialogShowGoodsVisible">
        <el-row>
          <el-col :span="6" style="margin: 0px 5px 0px 5px;" v-for="(goods, index) in goodsList" :key="goods.id">
            <el-card :body-style="{ padding: '0px' }" style="margin: 0px 5px 0px 5px;">
              <el-image :src="goods.goodsImg" fit="'contain'" />
              <div style="padding: 14px; min-width:180px;">
                <div class="bottom clearfix">
                  <!-- <el-button type="text" class="button">操作按钮</el-button> -->
                  <el-radio v-model="tempGoods.id" :label="goods.id">{{ goods.goodsName }}</el-radio>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>

        <el-pagination background layout="prev, pager, next" @current-change="handleQueryGoodsCurrentChange"
          :total="query.goods.total" :size-page="handleQueryGoodsSizeChange" :page-size="query.goods.pageSize">
        </el-pagination>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogShowGoodsVisible = false">取 消</el-button>
          <el-button type="primary" @click="getSKUGoodsSelected">确 定</el-button>
        </div>
      </el-dialog>
    </div>

    <div class="block">
      <!--弹框-->
      <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogShowGoodsSpecificationVisable">
        <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
          <el-table-column align="center" label="序号" width="95">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="规格组编号" width="110">
            <template slot-scope="scope">
              {{ scope.row.groupId }}
            </template>
          </el-table-column>
          <el-table-column label="显示区域" width="110">
            <template slot-scope="scope">
              {{ scope.row.displayArea }}
            </template>
          </el-table-column>
          <el-table-column label="参数名称" width="110">
            <template slot-scope="scope">
              {{ scope.row.parameterName }}
            </template>
          </el-table-column>
          <el-table-column label="所属组织" width="110">
            <template slot-scope="scope">
              {{ scope.row.organId }}
            </template>
          </el-table-column>
          <el-table-column label="组织路径" width="110">
            <template slot-scope="scope">
              {{ scope.row.organPath }}
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getList, doDelete, doEdit, doLanuch, putGoodsPriceOnSale, putGoodsPriceSoldOut } from '@/api/GoodsPrice/'
import { getList as queryGoodsList } from '@/api/Goods/'
import { getGoodsTypeTree } from '@/api/GoodsType'
import { queryForList as querySpecificationGroupList } from '@/api/goodsSpecificationGroup'
import { getList as queryGoodsTypeSpecification } from '@/api/GoodsSpecification/'
import { getList as queryGoodsTypeSpecificationItem, queryForList as queryGoodsSpecificationItemForList } from '@/api/GoodsSpecificationItem/'
import { queryForList as queryGoodsTypePropsForList, getList as queryGoodsTypePropsPage } from '@/api/goodsTypeProps'
import { queryForList as queryGoodsTypePropsValueForList } from '@/api/goodsTypePropsValue/'
import { queryForList as queryGoodsLinkPropsForList } from '@/api/goodsLinkProps/'
import { queryForList as queryGoodsLinkPropsValueForList } from '@/api/goodsLinkPropsValue/'
import { queryForList as queryGoodsLinkSpecificationForList } from '@/api/goodsLinkSpecification/'
import { queryForList as queryGoodsLinkSpecificationItemForList } from '@/api/goodsLinkSpecificationItem/'
import { query as queryGoodsExtByGoods } from '@/api/goodsExt/'

import { getDictionaryGroup } from '@/api/dictionary'
import { getOrganId, getTenantId, getOrganPath, getCurrentLoginUserId, handleBuildTreeDataStruct, getSuperManagerId, getSelectedNodes, getSelectedNodesObject, getSystemErrorCode } from '@/api/utils'
import { getTenantList, getToken, getOrganList, getDictionary, translateOrganId2OrganName } from '@/utils/auth'
import localStorageUtil from '@/utils/localStorageUtil'
import sessionStorageUtil from '@/utils/sessionStorageUtil'

export default {
  data() {
    return {
      list: null,
      listLoading: true,
      total: 5,
      currentPage: 1,
      pageSize: 10,
      dialogFormVisible: false,
      addForVisible: false,
      organTree: [],
      dialogShowGoodsVisible: false,
      dialogShowGoodsSpecificationVisable: false,
      dialogFormShowGoodsSpecificationVisible: false,
      dialogShowGoodsSpecificationItemVisable: false,
      dialogFormShowGoodsPropsVisible: false,
      activeNames: '',
      direction: 'rtl',
      drawer: false,
      goodsList: [],
      goodsSpecificationList: [],
      chooseSpecificationNodes: [],
      goodsSpecificationItems: [],
      goodsTypePropsValueList: [],
      goodsTypeSpecificationItemList: [],
      goodsTypePropsList: [],
      chooseGoodsTypePropsNodes: [],
      skuGoods: [],
      propValueMap: {},
      specificationItemMap: {},
      chooseSpecificationNodesMap: {},
      choosePropNodesMap: {},
      desartesProductOfProps: [],
      desartesProductOfSpecifications: [],
      skuPropsList: [],
      skuSpecificationList: [],
      dialogVisible: false,
      dialogImageUrl: '',
      step: 1,
      skuDatas: [],
      selectionsToOnline: [],
      fileUloadParams: { organId: getOrganId(), createBy: getCurrentLoginUserId() },
      form: {
        id: '',
        goodsId: '',
        goodsName: '',
        goodsCode: '',
        organId: '',
        organPath: '',
        goodsTypeId: '',
        goodsTypePath: '',
        isDeleted: '',
        type: '',
        createBy: '',
        createDate: '',
        updateBy: '',
        updateDate: '',
        remark: '',
        price: ''
      },
      skuPropsSpecifications: {
        props: [],
        specifications: []
      },
      tempGoods: {
        id: '',
        organId: '',
        organPath: '',
        organName: '',
        goodsTypeId: '',
        goodsTypePath: '',
        goodsName: '',
        supplierId: '',
        goodsImg: '',
        goodsDescribe: '',
        unit: '',
        unitValue: '',
        productionPlace: '',
        sys: '',
        isDeleted: '',
        quote: '',
        createBy: '',
        createDate: '',
        updateBy: '',
        updateDate: '',
        measurementType: '',
        remark: '',
      },
      props: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '组织',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      organTreeProps: {
        children: 'children',
        label: 'organName',
        url: 'url'
      },
      tenantProps: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '租户',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      supplierProps: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '租户',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      organFormOptions: [],
      tenantOptions: [],
      organOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      supplierOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      organTreeProps: {
        children: 'children',
        label: 'organName',
        url: 'url'
      },
      organQueryModel: 'selfAndSub',
      goodsTypeTreeOptionData: [{ id: '1', parentId: '2', typeName: '平台', children: [] }],
      specificationGroupOptionData: [{ id: '1', parentId: '2', typeName: '请选择规格组', children: [] }],
      goodsTypeTreeProps: { // 配置项（必选）
        value: 'id',
        label: 'typeName',
        children: 'children',
        checkStrictly: true,
        title: '组织'
        // disabled:true
      },
      specificationGroupTreeProps: { // 配置项（必选）
        value: 'id',
        label: 'name',
        children: 'children',
        checkStrictly: true,
        title: '规格组'
        // disabled:true
      },
      // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
      titleMap: {
        add: '新增',
        edit: '编辑'
      },
      // 新增和编辑弹框标题
      dialogStatus: '',
      query: {
        params: {
          id: '',
          goodsId: '',
          goodsName: '',
          goodsCode: '',
          organId: '',
          organPath: '',
          goodsTypeId: '',
          goodsTypePath: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: '',
          price: ''
        },
        goodsSpecificationGroup: {
          id: '',
          name: '',
          organId: '',
          organIds: [],
          organPath: '',
          tenantId: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: ''
        },
        goodsSpecification: {
          id: '',
          groupId: '',
          displayArea: '',
          parameterName: '',
          parameterCode: '',
          goodsTypeId: '',
          organId: '',
          organPath: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: '',
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        goodsSpecificationItem: {
          tenantId: '',
          organId: '',
          organPath: '',
          specificationId: '',
          specificationIds: [],
          total: 5,
          currentPage: 1,
          pageSize: 10
        },
        goods: {
          id: '',
          organId: '',
          tenantId: '',
          organPath: '',
          organName: '',
          goodsTypeId: '',
          goodsTypePath: '',
          goodsName: '',
          supplierId: '',
          goodsImg: '',
          goodsDescribe: '',
          unit: '',
          unitValue: '',
          productionPlace: '',
          sys: '',
          isDeleted: '',
          quote: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          measurementType: '',
          remark: '',
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        goodsTypeProps: {
          id: '',
          goodsTypeId: '',
          goodsTypePath: '',
          propName: '',
          propCode: '',
          organId: '',
          organPath: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: '',
          isMust: null,
          isMutilSelect: null,
          isNav: null,
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        goodsLinkProps: {
          goodsId: '',
          organId: '',
          organPath: '',
          propsId: '',
          status: '',
          tenantId: ''
        },
        goodsLinkPropsValue: {
          goodsId: '', //商品编号,
          goodsPriceId: '', //关联组织商品价格（理论上这个字段是t_goods_price_organ的编号）,
          id: '', //,
          organId: '', //所属组织,
          organPath: '', //组织路径,
          propsId: '', //,
          propsIds: [],
          propsValue: '', //,
          propsValueId: '', //属性编号,
          status: '', //,
          tenantId: '',
        },
        goodsLinkSpecification: {
          goodsId: '',
          id: '',
          organId: '',
          organPath: '',
          specificationId: '',
          status: '',
          tenantId: '',
        },
        goodsLinkSpecificationItem: {
          specificationIds: [],
          goodsId: '',
          goodsPriceId: '',
          id: '',
          organId: '',
          organPath: '',
          specificationId: '',
          specificationItemId: '',
          specificationValue: '',
          status: '',
          tenantId: ''
        },
        goodsExt: {
          goodsId: '',
          id: '',
          organId: '',
          organPath: '',
          parentId: '',
          status: '',
          tenantId: ''
        },
        goodsTypePropsItem: {
          id: '',
          goodsPropsId: '',
          goodsPropsValue: '',
          goodsPropsIds: [],
          organId: '',
          organPath: '',
          isDeleted: '',
          createBy: '',
          createDate: '',
          updateBy: '',
          updateDate: '',
          remark: '',
          total: 5,
          currentPage: 1,
          pageSize: 10,
        },
        timeValue: '',
        options: [{
          value: '1',
          label: '黄金糕'
        }, {
          value: '2',
          label: '双皮奶'
        }],
        value: ''
      }
    }
  },
  computed: {
    uploadHeader() {
      return {
        'Authorization': getToken(),
        'OrganId': getOrganId(),
        'tenantId': getTenantId(),
        'userId': getCurrentLoginUserId()
      }
    }
  }
  ,
  created() {
    this.initGoodsTypeTree()
    this.initOrganTree(() => {
      this.setOrganQueryType()
    }, getOrganPath())
    this.initOrganFormTree()
    this.handleFiltTenant()
    this.handleFiltSupplier()
    this.fetchData()
  },
  methods: {
    translateOrgan(row) {
      return translateOrganId2OrganName(row);
    },
    setOrganQueryType() {
      this.organQueryModel = localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL")
      this.organQueryModelChange(this.organQueryModel)
    },
    fetchData() {
      this.listLoading = true
      this.createOrganQuery()
      this.currentPage = this.currentPage || 1
      this.pageSize = this.pageSize || 10
      getList(this.query.params, this.currentPage, this.pageSize).then(response => {
        const data = response.data
        if (!data.entities || typeof data.successful != 'undefined') {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        this.total = data.totalCount
        this.pageSize = data.pageSize
        this.currentPage = data.currentPage
        this.list = data.entities
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.currentPage = 1
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.fetchData()
    },
    createOrganQuery() {
      // 选中了租户
      let tenantSelected = this.$refs['tenantTree'] && this.$refs['tenantTree'].getCheckedNodes() || []
      let organSelected = this.$refs['organTree'] && this.$refs['organTree'].getCheckedNodes() || []
      let that = this
      this.query.params.organId = null
      if (tenantSelected.length && tenantSelected[0]) {
        this.query.params.tenantId = tenantSelected[0].data.id
        if (organSelected.length && organSelected[0]) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length && organSelected[0]) {
              organSelected.forEach(function (element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length && organSelected[0]) {
            this.query.params.organPath = organSelected[0] && organSelected[0].data.organPath
          }
        }
      } else {
        this.query.params.tenantId = getTenantId()
        if (organSelected.length && organSelected[0]) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length && organSelected[0]) {
              organSelected.forEach(function (element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length && organSelected[0]) {
            this.query.params.organPath = organSelected[0].data.organPath
          }
        }
      }
      this.query.params.organId = this.query.params.organId || getOrganId()
      this.query.params.organPath = this.query.params.organPath || getOrganPath()
    },
    // 新增
    handleAdd() {
      // 显示弹框
      //this.dialogFormVisible = true
      this.drawer = true
      // 新增弹框标题
      this.dialogStatus = 'add'

      this.form.id = ''
      this.form.goodsId = ''
      this.form.goodsName = ''
      this.form.goodsCode = ''
      this.form.organId = ''
      this.form.organPath = ''
      this.form.isDeleted = ''
      this.form.createBy = ''
      this.form.createDate = ''
      this.form.updateBy = ''
      this.form.updateDate = ''
      this.form.remark = ''
      this.form.price = ''
      this.addForVisible = false
    },
    // 编辑
    handleEdit(index, row) {
      console.log(index)
      console.log(row)
      this.form.id = row.id
      this.form.goodsId = row.goodsId
      this.form.goodsName = row.goodsName
      this.form.goodsCode = row.goodsCode
      this.form.organId = row.organId
      this.form.organPath = row.organPath
      this.form.isDeleted = row.isDeleted
      this.form.createBy = row.createBy
      this.form.createDate = row.createDate
      this.form.updateBy = row.updateBy
      this.form.updateDate = row.updateDate
      this.form.remark = row.remark
      this.form.price = row.price
      this.addForVisible = true
      // 显示弹框
      this.dialogFormVisible = true
      // 编辑弹框标题
      this.dialogStatus = 'edit'
    },
    handleDelete(index, row) {
      console.log(index)
      console.log(row)

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        doDelete(row.id).then(response => {
          const data = response.data
          console.log(data)
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleEditSave() {
      doEdit(this.form).then(response => {
        debugger
        console.log(response)
        const data = response.data
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })

          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        this.listLoading = false
        this.dialogFormVisible = false
      })
    },
    handleReset() {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    initOrganTree(fn, filter, that) {
      this.listLoading = true
      let data = getOrganList()
      if (filter) {
        data = data.filter(function (item, index) {
          return item.organPath.indexOf(filter) >= 0
        })
      }
      if (that && that.organFormOptions && that.organFormOptions.length >= 0) {
        that.organFormOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      } else {
        this.organOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      }
      this.listLoading = false
      if (fn) {
        fn()
      }
    },
    initOrganFormTree(fn, filter) {
      this.initOrganTree(fn, filter, this)
    },
    setOrganQueryType() {
      this.organQueryModelChange(localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL"))
    },
    selectOrgan(nodes) {
      let nodesInfo = this.$refs['organTree'].getCheckedNodes()
      let that = this
      this.query.params.organPath = ''
      this.query.params.organIds = []
      if (this.props.multiple) {
        this.query.params.organIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function (element) {
            that.query.params.organIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.organPath = nodesInfo[0].data.organPath
      }
    },
    selectTenant(nodes) {
      let nodesInfo = this.$refs['tenantTree'].getCheckedNodes()
      let that = this
      this.query.params.tenantId = ''
      this.query.params.tenantIds = []
      this.query.params.organId = null
      this.query.params.organIds = []
      this.query.params.organPath = null

      if (this.tenantProps.multiple) {
        this.query.params.tenantIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function (element) {
            that.query.params.tenantIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.tenantId = nodesInfo[0] && nodesInfo[0].data.id || getTenantId()
        this.initOrganTree(function () {
          that.setOrganQueryType()
        }, nodesInfo[0] && nodesInfo[0].data.organPath || getOrganPath())
      } else {
        this.initOrganTree(function () {
          that.setOrganQueryType()
        })
      }
    },
    chooseTenantForm(nodes) {
      let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
      this.form.tenantId = null
      let that = this
      if (nodesInfo.length) {
        this.form.tenantId = nodesInfo[0].data.id
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath, this.organFormOptions)
      } else {
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, null, this.organFormOptions)
      }
    },
    chooseTenant(form) {
      debugger
      let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
      form.tenantId = null
      let that = this
      if (nodesInfo.length) {
        form.tenantId = nodesInfo[0].data.id
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath, this.organFormOptions)
      } else {
        this.initOrganFormTree(function () {
          that.setOrganQueryType()
        }, null, this.organFormOptions)
      }
    },
    organQueryModelChange(organQueryModel) {
      if (organQueryModel == 'selected') {
        this.props.multiple = true
      } else if (organQueryModel == 'selfAndSub') {
        this.props.multiple = false
      }
    },
    chooseOrganForm(nodes) {
      let nodesInfo = this.$refs['organTreeForm'].getCheckedNodes()
      if (nodesInfo[0]) {
        this.form.organPath = nodesInfo[0].data.organPath
        this.form.organId = nodesInfo[0].data.id
        this.form.tenantId = nodesInfo[0].data.tenantId
      }
    },
    handleFiltTenant() {
      let data = getOrganList()
      this.tenantOptions = data.filter(function (item, index) {
        return item.type == 0 || item.type == 1;
      })
    },
    handleFiltSupplier() {
      debugger
      let data = getOrganList()
      this.supplierOptions = data.filter(function (item, index) {
        return item.type == 99;
      })
    },
    initGoodsTypeTree() {
      this.listLoading = true
      getGoodsTypeTree({ organId: getOrganId(), tenantId: getTenantId() }).then(response => {
        console.log(response)
        const data = response.data.data
        this.goodsTypeTreeOptionData = handleBuildTreeDataStruct(data, 'id', 'parentId')
        this.listLoading = false
      })
    },
    selectGoodsType(nodes) {
      let nodesInfo = this.$refs['goodsTypeTree'].getCheckedNodes()
      this.query.params.goodsTypeId = nodesInfo[0].data.id
      this.query.goods.goodsTypeId = nodesInfo[0].data.id
      this.handleQueryGoodsTypeProps()
    },

    selectSpecificationGroup() {
      let nodesInfo = this.$refs['specificationGroupTree'].getCheckedNodes()
      this.query.goodsSpecification.groupId = nodesInfo[0].data.id
    },
    selectSupplier(nodes) {
      let nodesInfo = this.$refs['supplierTree'].getCheckedNodes()
      if (nodesInfo.length) {
        this.query.params.supplierId = nodesInfo[0].data.id
      } else {
        this.query.params.supplierId = null
      }
    },
    getGoodsType(form) {
      let nodesInfo = this.$refs['goodsTypeTreeForm'].getCheckedNodes()
      form.goodsTypeId = nodesInfo[0].data.id
      form.goodsTypePath = nodesInfo[0].data.typePath
    },
    handleClose(done) {
      this.$confirm('确认关闭SKU发布操作吗？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    handleShowGoodsList() {
      this.dialogShowGoodsVisible = true
      this.query.goods.organId = getOrganId()
      this.query.goods.organPath = getOrganPath()
      this.query.goods.tenantId = getTenantId()
      this.handleQueryGoodsList()
    },
    handleQueryGoodsList() {
      this.listLoading = true
      queryGoodsList(this.query.goods, this.query.goods.currentPage, this.query.goods.pageSize).then(response => {
        const data = response.data
        if (!data.entities || typeof data.successful != 'undefined') {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        this.query.goods.total = data.totalCount
        this.query.goods.pageSize = data.pageSize
        this.query.goods.currentPage = data.currentPage
        this.goodsList = data.entities
        this.listLoading = false
      });
    },
    handleQueryGoodsCurrentChange(val) {
      this.query.goods.currentPage = val
      this.handleQueryGoodsList()
    },
    handleQueryGoodsSizeChange(val) {
      this.query.goods.currentPage = 12
      this.query.goods.pageSize = val
      this.handleQueryGoodsList()
    },
    handleShowGoodsSpecification() {
      this.dialogFormShowGoodsSpecificationVisible = true
      this.query.goodsSpecificationGroup.organId = getOrganId()
      this.query.goodsSpecificationGroup.organPath = getOrganPath()
      this.query.goodsSpecificationGroup.tenantId = getTenantId()
      this.handleQueryGoodsSpecificationGroup()
    },
    handleChange() {

    },
    handleQueryGoodsSpecificationGroup() {
      querySpecificationGroupList(this.query.goodsSpecificationGroup).then(response => {
        let data = response.data
        if (data.successful) {
          this.specificationGroupOptionData = handleBuildTreeDataStruct(data.data, 'id', 'parentId')
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      });
    },
    handleQueryGoodsTypeSpecification() {
      this.listLoading = true
      this.query.goodsSpecification.currentPage = 1
      this.query.goodsSpecification.pageSize = 10
      this.query.goodsSpecification.organId = getOrganId()
      this.query.goodsSpecification.organPath = getOrganPath()
      this.query.goodsSpecification.tenantId = getTenantId()
      queryGoodsTypeSpecification(this.query.goodsSpecification,
        this.query.goodsSpecification.currentPage,
        this.query.goodsSpecification.pageSize
      ).then(response => {
        const pager = response.data
        this.goodsSpecificationList = pager.entities
        this.query.goodsSpecification.pageSize = pager.pageSize
        this.query.goodsSpecification.total = pager.totalCount
        this.query.goodsSpecification.currentPage = pager.currentPage
        this.listLoading = false
      })

    },

    handleGoodsSpecificationToSKU() {

      this.handleQueryGoodsSpecificationItem()

    },
    handleQueryGoodsSpecificationSizeChange(val) {

    },
    handleQueryGoodsSpecificationCurrentChange(val) {

    },
    handleShowGoodsSpecificationItem(index, row) {

      this.dialogShowGoodsSpecificationItemVisable = true
      this.query.goodsSpecificationItem.specificationId = row.id
      this.query.goodsSpecificationItem.specificationIds = []
      this.query.goodsSpecificationItem.organId = row.organId || getOrganId()
      this.query.goodsSpecificationItem.organPath = row.organPath || getOrganPath()
      this.query.goodsSpecificationItem.tenantId = row.tenantId || getTenantId()
      this.handleQueryGoodsTypeSpecificationItemPage()
    },
    handleQueryGoodsTypeSpecificationItemPage() {
      this.query.goodsSpecificationItem.currentPage = 1
      this.query.goodsSpecificationItem.pageSize = 10
      queryGoodsTypeSpecificationItem(this.query.goodsSpecificationItem,
        this.query.goodsSpecificationItem.currentPage,
        this.query.goodsSpecificationItem.pageSize).then(response => {
          console.log(response)
          const pager = response.data

          this.query.goodsSpecificationItem.pageSize = pager.pageSize
          this.query.goodsSpecificationItem.currentPage = pager.currentPage
          this.query.goodsSpecificationItem.total = pager.totalCount
          this.goodsTypeSpecificationItemList = pager.entities

        })
    },
    handleQueryItemValSizeChange(val) {
      this.query.goodsSpecificationItem.currentPage = 1
      this.query.goodsSpecificationItem.pageSize = val
      this.handleQueryGoodsTypeSpecificationItemPage()
    },
    handleQueryItemCurrentChange(val) {
      this.query.goodsSpecificationItem.currentPage = val
      this.handleQueryGoodsTypeSpecificationItemPage()
    },
    handleGoodsSpecifiactionSelectionChange(selectedNodes) {
      this.chooseSpecificationNodes = selectedNodes
    },
    handleGoodsPropSelectionChange(selectedNodes) {
      this.chooseGoodsTypePropsNodes = selectedNodes
    },
    handleQueryGoodsSpecificationItem() {
      this.chooseSpecificationNodesMap = {}
      this.specificationItemMap = {}
      this.query.goodsSpecificationItem.specificationIds = []
      this.query.goodsSpecificationItem.specificationId = ''
      if (this.chooseSpecificationNodes && this.chooseSpecificationNodes.length) {
        for (let i = 0; i < this.chooseSpecificationNodes.length; i++) {
          this.query.goodsSpecificationItem.specificationIds.push(this.chooseSpecificationNodes[i].id)
          this.chooseSpecificationNodesMap[this.chooseSpecificationNodes[i].id] = this.chooseSpecificationNodes[i]
          this.chooseSpecificationNodes[i]['specificationItems'] = []
          this.chooseSpecificationNodes[i]['specificationItemsSelected'] = []
        }
      }
      let that = this
      this.query.goodsSpecificationItem.organId = getOrganId()
      this.query.goodsSpecificationItem.organPath = getOrganPath()
      this.query.goodsSpecificationItem.tenantId = getTenantId()
      queryGoodsSpecificationItemForList(this.query.goodsSpecificationItem).then(response => {
        let data = response.data
        if (data.successful) {
          debugger
          that.goodsSpecificationItems = data.data
          for (let i = 0; i < that.goodsSpecificationItems.length; i++) {
            that.chooseSpecificationNodesMap[that.goodsSpecificationItems[i].specificationId]['specificationItems'].push(that.goodsSpecificationItems[i])
            that.chooseSpecificationNodesMap[that.goodsSpecificationItems[i].specificationId]['selected'] = true
            that.specificationItemMap[that.goodsSpecificationItems[i].id] = that.goodsSpecificationItems[i]
          }

        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      });
    },
    handleQueryGoodsTypeProps() {
      this.query.goodsTypeProps.goodsTypeId = this.query.goods.goodsTypeId
      this.query.goodsTypeProps.organId = getOrganId()
      this.query.goodsTypeProps.organPath = getOrganPath()
      this.query.goodsTypeProps.tenantId = getTenantId()
      this.query.goodsTypeProps.isMust = true
      queryGoodsTypePropsForList(this.query.goodsTypeProps).then(response => {
        const data = response.data
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.goodsTypePropsList = data.data
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
    },
    handleQueryGoodsTypePropsPage() {
      this.query.goodsTypeProps.goodsTypeId = this.query.goods.goodsTypeId
      this.query.goodsTypeProps.organId = getOrganId()
      this.query.goodsTypeProps.organPath = getOrganPath()
      this.query.goodsTypeProps.tenantId = getTenantId()
      //this.query.goodsTypeProps.isMust = true
      this.listLoading = true
      queryGoodsTypePropsPage(this.query.goodsTypeProps,
        this.query.goodsTypeProps.currentPage,
        this.query.goodsTypeProps.pageSize).then(response => {
          const data = response.data
          this.total = data.totalCount
          this.query.goodsTypeProps.pageSize = data.pageSize
          this.query.goodsTypeProps.currentPage = data.currentPage
          this.goodsTypePropsList = data.entities
          this.listLoading = false
        })
    },
    handleShowQueryGoodsTypeProps() {
      this.dialogFormShowGoodsPropsVisible = true
      this.handleQueryGoodsTypePropsPage()
    },

    handleQueryGoodsTypePropsItem() {
      this.choosePropNodesMap = {}
      this.propValueMap = {}
      this.query.goodsTypePropsItem.goodsPropsIds = []
      if (this.chooseGoodsTypePropsNodes && this.chooseGoodsTypePropsNodes.length) {
        for (let i = 0; i < this.chooseGoodsTypePropsNodes.length; i++) {
          this.query.goodsTypePropsItem.goodsPropsIds.push(this.chooseGoodsTypePropsNodes[i].id)
          this.choosePropNodesMap[this.chooseGoodsTypePropsNodes[i].id] = this.chooseGoodsTypePropsNodes[i]
          this.chooseGoodsTypePropsNodes[i]['goodsTypePropValues'] = []
          this.chooseGoodsTypePropsNodes[i]['goodsTypePropValuesSelected'] = []
        }
      }
      let that = this
      this.query.goodsTypePropsItem.organId = getOrganId()
      this.query.goodsTypePropsItem.organPath = getOrganPath()
      this.query.goodsTypePropsItem.tenantId = getTenantId()
      queryGoodsTypePropsValueForList(this.query.goodsTypePropsItem).then(response => {
        let data = response.data
        if (data.successful) {
          that.goodsTypePropsValueList = data.data
          for (let i = 0; i < that.goodsTypePropsValueList.length; i++) {
            that.choosePropNodesMap[that.goodsTypePropsValueList[i].goodsPropsId]['goodsTypePropValues'].push(that.goodsTypePropsValueList[i])
            that.choosePropNodesMap[that.goodsTypePropsValueList[i].goodsPropsId]['selected'] = true
            that.propValueMap[that.goodsTypePropsValueList[i].id] = that.goodsTypePropsValueList[i]
          }
        } else {
          that.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        that.dialogFormShowGoodsPropsVisible = false
      })

    },

    handleGoodsTypePropsToSKU() {
      this.handleQueryGoodsTypePropsItem()
    },
    getSKUGoodsSelected() {
      let that = this
      this.$confirm('确定选择该商品发布SKU吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        if (that.goodsList && that.goodsList.length) {
          for (let i = 0; i < that.goodsList.length; i++) {
            if (that.tempGoods.id === that.goodsList[i].id) {
              that.tempGoods = that.goodsList[i]
              this.handleQueryGoodsLinkProps()
              this.handleQueryGoodsLinkSpecifications()
              this.handleQueryGoodsExtByGoods()
              this.form.goodsName = that.tempGoods.goodsName
              this.form.goodsTypeId = that.tempGoods.goodsTypeId
              this.form.goodsTypePath = that.tempGoods.goodsTypePath
              break;
            }
          }
        }
        this.dialogShowGoodsVisible = false
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    handleQueryGoodsLinkSpecifications() {
      debugger
      this.query.goodsLinkSpecification.goodsId = this.tempGoods.id
      this.query.goodsLinkSpecification.organId = this.tempGoods.organId || getOrganId()
      this.query.goodsLinkSpecification.organPath = this.tempGoods.organPath || getOrganPath()
      this.query.goodsLinkSpecification.tenantId = this.tempGoods.tenantId || getTenantId()
      this.query.goodsLinkPropsValue.goodsId = this.tempGoods.id
      queryGoodsLinkSpecificationForList(this.query.goodsLinkSpecification).then(response => {
        debugger
        let gateway = response.data
        if (gateway.successful) {
          this.handleQueryGoodsLinkSpecificationItem(gateway.data)
        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleQueryGoodsLinkSpecificationItem(data) {
      let tempChooseGoodsTypeSpecificationNodes = data
      this.chooseSpecificationNodesMap = {}
      this.specificationItemMap = {}
      this.query.goodsSpecificationItem.specificationIds = []
      this.query.goodsSpecificationItem.specificationId = ''
      if (data && data.length) {
        for (let i = 0; i < data.length; i++) {
          data[i].id = data[i].specificationId
          data[i].parameterName = data[i].specificationName
          this.query.goodsLinkSpecificationItem.specificationIds.push(data[i].id)
          this.chooseSpecificationNodesMap[data[i].id] = data[i]
          data[i]['specificationItems'] = []
          data[i]['specificationItemsSelected'] = []
        }
      }
      let that = this
      this.query.goodsLinkSpecificationItem.goodsId = this.tempGoods.id
      this.query.goodsLinkSpecificationItem.organId = getOrganId()
      this.query.goodsLinkSpecificationItem.organPath = getOrganPath()
      this.query.goodsLinkSpecificationItem.tenantId = getTenantId()
      queryGoodsLinkSpecificationItemForList(this.query.goodsLinkSpecificationItem).then(response => {
        let data = response.data
        if (data.successful) {
          that.goodsSpecificationItems = data.data
          for (let i = 0; i < this.goodsSpecificationItems.length; i++) {
            that.chooseSpecificationNodesMap[that.goodsSpecificationItems[i].specificationId]['specificationItems'].push(that.goodsSpecificationItems[i])
            that.chooseSpecificationNodesMap[that.goodsSpecificationItems[i].specificationId]['selected'] = true
            that.specificationItemMap[that.goodsSpecificationItems[i].id] = that.goodsSpecificationItems[i]
          }

          this.chooseSpecificationNodes = tempChooseGoodsTypeSpecificationNodes
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      });
    },
    handleQueryGoodsLinkProps() {
      this.query.goodsLinkProps.goodsId = this.tempGoods.id
      this.query.goodsLinkProps.organId = this.tempGoods.organId || getOrganId()
      this.query.goodsLinkProps.organPath = this.tempGoods.organPath || getOrganPath()
      this.query.goodsLinkProps.tenantId = this.tempGoods.tenantId || getTenantId()
      this.query.goodsLinkPropsValue.goodsId = this.tempGoods.id
      queryGoodsLinkPropsForList(this.query.goodsLinkProps).then(response => {
        let gateway = response.data
        if (gateway.successful) {
          let data = gateway.data
          data.filter(function (item) {
            item.id = item.propsId
          })
          this.handleQueryGoodsLinkPropsValues(data)
        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleQueryGoodsLinkPropsValues(data) {

      let tempChooseGoodsTypePropsNodes = data
      this.choosePropNodesMap = {}
      this.propValueMap = {}
      this.query.goodsLinkPropsValue.propsIds = []
      if (data && data.length) {
        for (let i = 0; i < tempChooseGoodsTypePropsNodes.length; i++) {
          this.query.goodsLinkPropsValue.propsIds.push(tempChooseGoodsTypePropsNodes[i].id)
          this.choosePropNodesMap[tempChooseGoodsTypePropsNodes[i].id] = tempChooseGoodsTypePropsNodes[i]
          tempChooseGoodsTypePropsNodes[i]['goodsTypePropValues'] = []
          tempChooseGoodsTypePropsNodes[i]['goodsTypePropValuesSelected'] = []
        }
      }

      let that = this
      this.query.goodsLinkPropsValue.organId = getOrganId()
      this.query.goodsLinkPropsValue.organPath = getOrganPath()
      this.query.goodsLinkPropsValue.tenantId = getTenantId()
      queryGoodsLinkPropsValueForList(this.query.goodsLinkPropsValue).then(response => {
        let gateway = response.data
        if (gateway.successful) {
          that.goodsLinkPropsValueList = gateway.data
          for (let i = 0; i < gateway.data.length; i++) {
            gateway.data[i].id = gateway.data[i].propsValueId
            gateway.data[i].goodsPropsValue = gateway.data[i].propsValue
            gateway.data[i].goodsPropsId = gateway.data[i].propsId
            that.choosePropNodesMap[gateway.data[i].propsId]['goodsTypePropValues'].push(gateway.data[i])
            that.choosePropNodesMap[gateway.data[i].propsId]['selected'] = true
            that.propValueMap[gateway.data[i].propsValueId] = gateway.data[i]
          }
          that.chooseGoodsTypePropsNodes = tempChooseGoodsTypePropsNodes
          console.log(that.choosePropNodesMap)
        } else {
          that.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        that.dialogFormShowGoodsPropsVisible = false
      })
    },

    handleGoodsTypePropsChange(updatedVals) {
      console.log(updatedVals)
      let propMap = {}
      // 清除上次的选择
      for (let key in this.choosePropNodesMap) {
        this.choosePropNodesMap[key].goodsTypePropValuesSelected = []
      }
      // 此处对选择好的商品销售属性进行收集，准备做迪卡尔积运算
      for (let i = 0; i < updatedVals.length; i++) {
        this.choosePropNodesMap[this.propValueMap[updatedVals[i]].goodsPropsId]
          .goodsTypePropValuesSelected.push(this.propValueMap[updatedVals[i]])
      }

    },
    handleGoodsSpecificationItemChange(updatedVals) {
      // 清除上次的选择
      for (let key in this.chooseSpecificationNodesMap) {
        this.chooseSpecificationNodesMap[key].specificationItemsSelected = []
      }
      // 此处对选择好的商品规格进行收集，准备做迪卡尔积运算
      for (let i = 0; i < updatedVals.length; i++) {
        this.chooseSpecificationNodesMap[this.specificationItemMap[updatedVals[i]].specificationId]
          .specificationItemsSelected.push(this.specificationItemMap[updatedVals[i]])
      }
    },
    handleCreateDesartesProductOfProps() {
      let skuPropsList = []
      for (let key in this.choosePropNodesMap) {
        skuPropsList = this.handleDesartesProduct(this.choosePropNodesMap[key].goodsTypePropValuesSelected,
          skuPropsList)
      }
      this.skuPropsList = skuPropsList
    },
    handleCreateDesartesProductOfSpecifications() {
      let skuSpecificationList = []
      for (let key in this.chooseSpecificationNodesMap) {
        skuSpecificationList = this.handleDesartesProduct(this.chooseSpecificationNodesMap[key].specificationItemsSelected,
          skuSpecificationList)
      }
      this.skuSpecificationList = skuSpecificationList
    },
    handleDesartesProduct(elements, arr) {
      let tempArrResult = []
      if (elements && elements.length && arr && arr.length) {
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < elements.length; j++) {
            let tempArr = []
            tempArr.push(arr[i])
            tempArr.push(elements[j])
            tempArrResult.push(tempArr)
          }
        }
      } else if (arr && arr.length && (!elements || !elements.length)) {
        for (let i = 0; i < arr.length; i++) {
          let tempArr = []
          tempArr.push(elements[i])
          tempArrResult.push(tempArr)
        }
      } else if ((!arr || !arr.length) && elements && elements.length) {
        for (let i = 0; i < elements.length; i++) {
          let tempArr = []
          tempArr.push(elements[i])
          tempArrResult.push(tempArr)
        }
      }
      return tempArrResult;
    },
    handleCopyArr(arr) {
      let copyArr = []
      for (let i = 0; i < arr.length; i++) {
        copyArr.push(arr[i])
      }
      return copyArr;
    },
    handleCheckGoodsTypeProps() {

      if (!this.skuPropsSpecifications.props.length) {
        this.$message({
          type: 'danger',
          message: '请选择商品类型属性!'
        })
        return;
      }
      this.handleGoTONextStep()
      // 生成属性迪卡尔积
      this.handleCreateDesartesProductOfProps()
      this.handleTilingProps()
    },

    handleTitling(elements, container) {
      console.log(elements)
      if (elements && elements.length) {
        for (let i = 0; i < elements.length; i++) {
          let tempContainer = []
          this.handleTilingArr(elements[i], tempContainer)
          container.push(tempContainer)

        }
      }
    },
    // 平铺数组元素
    handleTilingArr(arr, container) {
      if (arr && arr.constructor === Array) {
        for (let i = 0; i < arr.length; i++) {
          this.handleTilingArr(arr[i], container)
        }
      } else if (arr) {
        container.push(arr)
      }
    },
    handleTilingProps() {
      this.desartesProductOfProps = []
      this.handleTitling(this.skuPropsList, this.desartesProductOfProps)
    },
    handleTilingSpecifications() {
      this.desartesProductOfSpecifications = []
      this.handleTitling(this.skuSpecificationList, this.desartesProductOfSpecifications)

    },
    handleCheckGoodsSpecification() {

      if (!this.skuPropsSpecifications.specifications.length) {
        this.$message({
          type: 'danger',
          message: '请选择商品规格属性!'
        })
        return;
      }
      this.handleGoTONextStep()
      // 生成规格迪卡尔积
      this.handleCreateDesartesProductOfSpecifications()
      this.handleTilingSpecifications()
      this.handleCreateSkuDatas()

    },
    handleCreateSkuDatas() {
      let skuDatas = []
      for (let i = 0; i < this.desartesProductOfProps.length; i++) {
        let skuData = {}
        for (let key in this.tempGoods) {
          if (key == 'id') {
            skuData['goodsId'] = this.tempGoods[key]
          } else {
            skuData[key] = this.tempGoods[key]
          }
        }
        skuData['propValues'] = []
        skuData['props'] = []
        skuData['imageList'] = []
        skuData['specifications'] = []
        skuData['specificationItems'] = []

        for (let j = 0; j < this.desartesProductOfSpecifications.length; j++) {
          for (let k = 0; k < this.desartesProductOfSpecifications[j].length; k++) {
            skuData.specificationItems.push(this.desartesProductOfSpecifications[j][k])
            skuData.specifications.push(this.chooseSpecificationNodesMap[this.desartesProductOfSpecifications[j][k].specificationId])
          }
        }

        for (let j = 0; j < this.desartesProductOfProps[i].length; j++) {
          skuData.goodsName = skuData.goodsName + "_" + this.desartesProductOfProps[i][j].goodsPropsValue
          skuData.propValues.push(this.desartesProductOfProps[i][j])
          skuData.props.push(this.choosePropNodesMap[this.desartesProductOfProps[i][j].goodsPropsId])
        }

        skuDatas.push(skuData)
      }
      this.skuGoods = skuDatas
    },
    handleGoTONextStep() {
      if (this.step < 3) {
        this.step = ++this.step
      }
    },
    handleGoTOPreStep() {
      if (this.step > 1) {
        this.step = --this.step
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleQueryGoodsExtByGoods() {
      this.query.goodsExt.goodsId = this.tempGoods.id
      this.query.goodsExt.organId = getOrganId()
      this.query.goodsExt.organPath = getOrganPath()
      this.query.goodsExt.tenantId = getTenantId()
      queryGoodsExtByGoods(this.query.goodsExt).then(response => {
        const gateway = response.data
        if (gateway.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          if (gateway.data) {
            this.form.packHeight = gateway.data.packHeight
            this.form.packLength = gateway.data.packLength
            this.form.packWidth = gateway.data.packWidth
            this.form.netWeight = gateway.data.netWeight
            this.form.width = gateway.data.width
            this.form.length = gateway.data.length
            this.form.height = gateway.data.height
            this.form.grossWeight = gateway.data.grossWeight
          }
        } else {
          this.$message({
            type: 'info',
            message: gateway.description || getSystemErrorCode(gateway.status)
          })
        }
      })
    },
    handleDeleteSku(index, row) {
      if (this.skuGoods && this.skuGoods.length > 0) {
        this.skuGoods.splice(index, 1);
        return;
      } else {
        console.log(this.skuGoods, '为空无法删除元素')
      }
    },
    handleSubmitSKUs() {
      if (this.skuGoods && this.skuGoods.length <= 0) {
        this.$message({
          type: 'info',
          message: '请确认SKU己经正确编辑!'
        })
        return;
      }
      this.$confirm('确定提交SKU吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {

        for (let i = 0; i < this.skuGoods.length; i++) {
          this.skuGoods[i].propValues = JSON.stringify(this.skuGoods[i].propValues)
          this.skuGoods[i].props = JSON.stringify(this.handleSimplifySkuProps(this.skuGoods[i].props))
          this.skuGoods[i].specifications = JSON.stringify(this.skuGoods[i].specifications)
          this.skuGoods[i].specificationItems = JSON.stringify(this.skuGoods[i].specificationItems)
          this.skuGoods[i].goodsCode = this.skuGoods[i].code
          this.skuGoods[i]['packHeight'] = this.form.packHeight
          this.skuGoods[i]['packLength'] = this.form.packLength
          this.skuGoods[i]['packWidth'] = this.form.packWidth
          this.skuGoods[i]['netWeight'] = this.form.netWeight
          this.skuGoods[i]['width'] = this.form.width
          this.skuGoods[i]['length'] = this.form.length
          this.skuGoods[i]['height'] = this.form.height
          this.skuGoods[i]['grossWeight'] = this.form.grossWeight

        }
        doLanuch({ entities: this.skuGoods }).then(response => {
          const data = response.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }
        })
        this.dialogShowGoodsVisible = false
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    uploadFileOnSuccess(response, file, fileList) {
      if (!response.data.successful) {
        this.$message({
          type: 'warning',
          message: response.description
        })
        return;
      }
      this.form.goodsImg = response.data.data.fileUrl
    },
    uploadImageOnSuccess(response, file, fileList) {
      if (!response.data.successful) {
        this.$message({
          type: 'warning',
          message: response.description
        })
        return;
      }
      // this.goodsImg.imgUrl = response.data.data.fileUrl
      console.log(this.skuGoods)
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    handleSelectionChange(selections) {
      this.selectionsToOnline = selections
    },
    handleToOnSale() {
      if (!this.selectionsToOnline || !this.selectionsToOnline.length) {
        this.$message({
          type: 'warning',
          message: "请在列表中选择需要上线的SKU"
        })
        return;
      }
      this.$confirm('操作将会把商品SKU上架, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let skuIdArray = []
        for (let index = 0; index < this.selectionsToOnline.length; index++) {
          const element = this.selectionsToOnline[index];
          skuIdArray.push(element.id)
        }
        this.handleBatchPutOnSale(skuIdArray);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消商品SKU上架'
        })
      })
    },
    handleToSoldOut() {
      if (!this.selectionsToOnline || !this.selectionsToOnline.length) {
        this.$message({
          type: 'warning',
          message: "请在列表中选择需要下架的SKU"
        })
        return;
      }

      this.$confirm('操作将会把商品SKU下架, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let skuIdArray = []
        for (let index = 0; index < this.selectionsToOnline.length; index++) {
          const element = this.selectionsToOnline[index];
          skuIdArray.push(element.id)
        }
        this.handleBatchPutSoldOut(skuIdArray);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消商品SKU下架'
        })
      })



    },
    handleSimplifySkuPropValues(propValues) {
      if (propValues && propValues.length) {
        for (let i = 0; i < propValues.length; i++) {


          goodsTypePropValues

          goodsTypePropValuesSelected
        }
      }
    },
    handleSimplifySkuProps(props) {
      if (props && props.length) {
        let propJsons = JSON.stringify(props)
        let propsTemp = JSON.parse(propJsons);
        for (let i = 0; i < propsTemp.length; i++) {
          delete propsTemp[i].goodsTypePropValues
          delete propsTemp[i].goodsTypePropValuesSelected
        }
        return propsTemp;
      }
      return props;
    },
    handleBatchEditSkuPropertyValue(column, event) {
      console.log(column)
    },
    handleBatchPutOnSale(selectionsToOnline) {
      let skuOnSale = {
        organId: getOrganId(),
        tenantId: getTenantId(),
        skuIds: selectionsToOnline,
        updateBy: getCurrentLoginUserId()
      }
      putGoodsPriceOnSale(skuOnSale).then(response => {
        debugger
        const data = response.data
        console.log(data)
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
    },
    handleBatchPutSoldOut(selectionsToSoldOut) {
      let skuSoldOut = {
        organId: getOrganId(),
        tenantId: getTenantId(),
        skuIds: selectionsToSoldOut,
        updateBy: getCurrentLoginUserId()
      }
      putGoodsPriceSoldOut(skuSoldOut).then(response => {
        debugger
        const data = response.data
        console.log(data)
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
    },
    handlePutOnSale(index, row) {
      this.$confirm('操作将会把商品SKU上架, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let skuOnSale = {
        organId: getOrganId(),
        tenantId: getTenantId(),
        skuIds: [],
        updateBy: getCurrentLoginUserId()
      }
      skuOnSale.skuIds.push(row.id)
      putGoodsPriceOnSale(skuOnSale).then(response => {
        const data = response.data
        console.log(data)
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消商品SKU上架'
        })
      })

    },
    handlePutSoldOut(index, row) {

      this.$confirm('操作将会把商品SKU下架, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        let skuSoldOut = {
        organId: getOrganId(),
        tenantId: getTenantId(),
        skuIds: [],
        updateBy: getCurrentLoginUserId()
      }
      skuSoldOut.skuIds.push(row.id)
      putGoodsPriceSoldOut(skuSoldOut).then(response => {
        const data = response.data
        console.log(data)
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消商品SKU下架'
        })
      })
      
    },
  }
}
</script>
<style>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.radio {
  padding: 0;
  float: right;
}


.image {
  height: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>